package com.adroid.lespetitspedestres;




import android.app.Activity;
import android.app.FragmentManager;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.ImageButton;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;

public class MainActivity extends Activity implements OnClickListener{

	/**
	 * @param args
	 */
	long timeWhenStopped = 0;
    
	 @Override
	    protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.activity_main);
	        
	        final ImageButton buttonPlay = (ImageButton) findViewById(R.id.imagePlay);
	        final ImageButton buttonPause = (ImageButton) findViewById(R.id.imagePause);
	        final ImageButton buttonStop = (ImageButton) findViewById(R.id.imageStop);
	        final Chronometer Mchronometer = (Chronometer) findViewById(R.id.chronometer1);
	        
		    buttonPlay.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Mchronometer.setBase(SystemClock.elapsedRealtime()
                            +timeWhenStopped);
					Mchronometer.start();
					buttonPause.setVisibility(ImageButton.VISIBLE);
					buttonPlay.setVisibility(ImageButton.INVISIBLE);
				}
			});
		    
		    buttonPause.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					timeWhenStopped = Mchronometer.getBase() - SystemClock.elapsedRealtime();
			        Mchronometer.stop();
					buttonPause.setVisibility(ImageButton.INVISIBLE);
					buttonPlay.setVisibility(ImageButton.VISIBLE);
				}
			});
		    
		    buttonStop.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Mchronometer.setBase(SystemClock.elapsedRealtime());
		            Mchronometer.stop();
		            timeWhenStopped = 0;
				}
			});
	    }


	    @Override
	    public boolean onCreateOptionsMenu(Menu menu) {
	        // Inflate the menu; this adds items to the action bar if it is present.
	    	super.onCreateOptionsMenu(menu);
	    	  MenuInflater inflater = getMenuInflater();
	    	  inflater.inflate(R.menu.main, menu);
	    	  return true;
	    }


		@Override
		public void onClick(DialogInterface dialog, int which) {
			// TODO Auto-generated method stub
			
		}


		
	   
		
	    
	    

}
